<div class="modal-body">
	<form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="id" id="userinfoId">
		<input type="hidden" name="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<div class="box-body">
			<div class="col-md-6">
				<div class="form-group">
					<label for="name" class="col-sm-3 control-label">用户姓名</label>

					<div class="col-sm-8">
						<input type="text" class="form-control" id="name" name="name" placeholder="用户姓名">
					</div>
				</div>
				<div class="form-group">
					<label for="login_name" class="col-sm-3 control-label">登录账号</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="login_name" name="login_name" placeholder="登录账号">
					</div>
				</div>
				<div class="form-group">
					<label for="mobile" class="col-sm-3 control-label">移动电话</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="mobile" name="mobile" placeholder="移动电话">
					</div>
				</div>
				<div class="form-group">
					<label for="area_code" class="col-sm-3 control-label">管辖区域</label>
					<div class="col-sm-8">
							<select id="area_code" class="form-control" name="area_code" style="margin-top:6px;">
								<option value="">请选择城市</option>
							</select>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<label for="email" class="col-sm-3 control-label">电子邮件</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="email" name="email" placeholder="电子邮件">
					</div>
				</div>
				<div class="form-group">
					<label for="address" class="col-sm-3 control-label">详细地址</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="address" name="address" placeholder="详细地址">
					</div>
				</div>
				<div class="form-group">
					<label for="description" class="col-sm-3 control-label">描述信息</label>
					<div class="col-sm-8">
						<textarea rows="5" class="form-control" id="description" name="description" placeholder="描述信息"/>
					</div>
				</div>
			</div>
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button type="button" class="btn btn-primary" data-btn-type="save" onclick="save_userinfo()">提交</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		view_userinfo();
	});
		
	function view_userinfo(){
		//从datatable上获取已经选择的条目
		if( Dtable_userinfo.rows('.selected').data().length > 0 ){
			var id = Dtable_userinfo.rows('.selected').data()[0].id;
			$("#userinfoId").val( id );
			
			if( id == "null" ||id == null || id == undefined || id == "0" ){
				return false;
			}
			//说明是查询
			$("#id").val(id);
			$("[name='btn_sys_config_delete']").attr("disabled", false);
			var url = "../../tbl_user/" + id;
			$.getJSON(url, null, function(json){
				//向页面上加载信息
				if( json && json.data ){
					var userinfo = json.data;
					$("#userinfoId").val(userinfo.id);
					$("#name").val(userinfo.name );
			 		$("#login_name").val(userinfo.login_name);
			 		$("#mobile").val(userinfo.mobile);
			 		$("#area_code").val(userinfo.area_code);
			 		$("#email").val(userinfo.email);
			 		$("#createTime").val(userinfo.createTime);
			 		$("#deleted").val(userinfo.deleted);
			 		$("#description").val(userinfo.description);
			 		$("#address").val(userinfo.address);
			 		//读取并且选中相应的信息
			 		initArea( "area_code", global.system_city_code, userinfo.area_code );
				}			
			});
		}
	}

	function initArea( sel_id, parent_code, sel_value ){
		var url = "../../tbl_area/list";
		var paramMap = {};
		paramMap.parent_code = parent_code;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
					  if( sel_value == this.area_code ){
						  $( "#" + sel_id ).append("<option value='"+ this.area_code +"' selected>"+ this.area_name +"</option>");
					  }else{
						  $( "#" + sel_id ).append("<option value='"+ this.area_code +"'>"+ this.area_name +"</option>");
					  }
				  });
			  }
		});
	}
	
	function save_userinfo( fn ){
		var userinfo = {};
		userinfo.id = $("#userinfoId").val();
		userinfo.name = $("#name").val();
		userinfo.login_name = $("#login_name").val();
		userinfo.mobile = $("#mobile").val();
		userinfo.area_code = $("#area_code").val();
		userinfo.email = $("#email").val();
		userinfo.address = $("#address").val();
		userinfo.description = $("#description").val();
		userinfo.createTime = $("#createTime").val();
		userinfo.deleted = $("#deleted").val();
		userinfo.province_code = global.system_provinde_code;
		userinfo.city_code = global.system_city_code;
		var json_data = JSON.stringify( userinfo );
		var url = "../../tbl_user/save";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert(json.message);
				 $("#userinfo_main").load("system/userinfo_list.html");
				 dialog_close();
				 if(fn){fn();}
			  }
		});
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>